home *** CD-ROM | disk | FTP | other *** search
Text File | 1993-05-04 | 4.6 KB | 213 lines | [TEXT/MPS ] |
- PROGRAM TestDrag;
- USES
- MemTypes, QuickDraw, OSIntf, ToolIntf, PackIntf,
- LtoLDragUnit;
-
- CONST
- kDialogID = 128;
- B_OK = 1;
- kReturn = 13;
- kEnter = 3;
- kInvalidDrag= $8000;
-
- VAR
- gDragDialog : DialogPtr;
- ExitDialog : BOOLEAN;
-
- {------------------------------------------------}
-
- FUNCTION FindCell(VAR Selected_Cell : Point;
- TheList : ListHandle) : BOOLEAN;
- BEGIN
- SetPt(Selected_Cell, 0, 0);
- FindCell:= LGetSelect(TRUE, Selected_Cell,
- TheList);
- END;
-
- {------------------------------------------------}
-
- PROCEDURE AddListString(theString:Str255; VAR
- theList:ListHandle; AddWhere : Integer);
- {This is a routine used to add strings to an }
- {existing list}
- VAR
- cSize : Point;
- Whichcell : Point;
- BEGIN
- IF (theList <> NIL) THEN
- BEGIN
- cSize.h := 0;
- cSize.v := LAddRow(1, AddWhere, theList);
- LSetCell(@TheString[1], length(TheString),
- cSize,theList);
- LDraw(cSize, theList); {Draw the new string}
- END;
- END;
-
- {------------------------------------------------}
-
- PROCEDURE DrawList (TheWindow : WindowPtr;
- TheItem : Integer);
- {Draw/Update the list which is connected to the useritem TheItem}
- VAR
- TempRect : Rect;
- DType : Integer;
- DItem : Handle;
- BEGIN
- IF gDragDialog = NIL THEN EXIT(DrawList);
- GetDItem(gDragDialog,TheItem,DType,DItem,
- tempRect);
- InsetRect(TempRect, -1, -1);
- FrameRect(TempRect);
- CASE TheItem OF
- U_List1:LUpdate(gDragDialog^.VisRgn, gList1);
- U_List2:LUpdate(gDragDialog^.VisRgn, gList2);
- U_List3:LUpdate(gDragDialog^.VisRgn, gList3);
- END;
- END;
-
- {------------------------------------------------}
-
- PROCEDURE MakeList (WhichList : Integer; VAR
- ListVar : ListHandle);
- VAR
- DType : Integer;
- DItem : Handle;
- RView, DBounds : Rect;
- CSize : Point;
- BEGIN
- GetDItem (gDragDialog, WhichList, DType, DItem,
- RView);
- SetRect(DBounds, 0, 0, 1, 0);
- SetPt(CSize, RView.Right - RView.Left, 16);
- ListVar := LNew (RView, DBounds, CSize, 0,
- gDragDialog, TRUE, FALSE, FALSE, TRUE);
- ListVar^^.lClikLoop := ProcPtr(@LtoLClickProc);
- ListVar^^.RefCon := WhichList;
- SetDItem(gDragDialog, WhichList, DType,
- Handle(@DrawList), RView);
- END;
-
- {------------------------------------------------}
-
- FUNCTION DetectListClick (VAR TheList :
- ListHandle; TheEvent : EventRecord) : BOOLEAN;
- {Detect clicks in a list}
- VAR
- MyPt : Point;
- BEGIN
- DetectListClick := FALSE;
- IF TheList=NIL THEN EXIT(DetectListClick);
- MyPt := theEvent.where;
- GlobalToLocal(MyPt);
- DetectListClick := LClick(myPt,
- theEvent.modifiers, TheList);
- END; {procedure}
-
- {------------------------------------------------}
-
- FUNCTION MyFilter (theDialog : DialogPtr; VAR
- theEvent : EventRecord; VAR itemHit : integer) :
- BOOLEAN;
- {catch clicks in the lists or 'ok' equivalents}
- VAR
- chCode : Integer;
- BEGIN
- MyFilter := FALSE;
- CASE theEvent.what OF
- KeyDown, AutoKey :
- WITH theEvent DO
- BEGIN
- chCode := BitAnd(message, CharCodeMask);
- IF (chCode = kEnter) | (chCode = kReturn)
- THEN
- ExitDialog := TRUE;
- END; {with}
- MouseDown :
- MyFilter:=DetectListClick(gList1,TheEvent) |
- DetectListClick(gList2,TheEvent) |
- DetectListClick(gList3,TheEvent);
- END; {case}
- END; {MyFilter}
-
- {------------------------------------------------}
-
- PROCEDURE DoDragDialog;
- VAR
- TempRect : Rect;
- SavePort : GrafPtr;
- ItemHit : Integer;
- i : Integer;
-
- FUNCTION ToStr (tempint : LongInt) : Str255;
- VAR
- Tempstr : Str255;
- BEGIN
- NumToString(tempint, tempstr);
- ToStr := tempstr;
- END;
-
- BEGIN
- ExitDialog := FALSE;
- SetRect (TempRect, 100, 100, 400, 400);
- gDragDialog := GetNewDialog (kDialogID, NIL,
- WindowPtr(-1));
- IF gDragDialog=NIL THEN EXIT (DoDragDialog);
- GetPort(SavePort);
- SetPort(gDragDialog);
- MakeList (U_List1, gList1);
- MakeList (U_List2, gList2);
- MakeList (U_List3, gList3);
- LDoDraw(FALSE, gList1);
- LDoDraw(FALSE, gList2);
- LDoDraw(FALSE, gList3);
- FOR i := 1 to 20 DO
- BEGIN
- AddListString(Concat('List 1, # ',ToStr(i)),
- gList1, i);
- AddListString(Concat('List 2, # ',ToStr(i)),
- gList2, i);
- AddListString(Concat('List 3, # ',ToStr(i)),
- gList3, i);
- END;
- LDoDraw(TRUE, gList1);
- LDoDraw(TRUE, gList2);
- LDoDraw(TRUE, gList3);
- SetDragEnvironment (gDragDialog);
-
- REPEAT
- ModalDialog(@MyFilter, itemHit);
- IF ItemHit = B_OK THEN ExitDialog := TRUE;
- UNTIL ExitDialog;
-
- LDispose(gList1);
- LDispose(gList2);
- LDispose(gList3);
- DisposDialog(gDragDialog);
- SetPort(SavePort);
- END;
-
- {------------------------------------------------}
-
- PROCEDURE Initialize;
- BEGIN
- InitGraf(@thePort);
- InitFonts;
- InitWindows;
- InitMenus;
- TEInit;
- InitDialogs(NIL);
- InitCursor;
- InitLtoLDrag;
- Flushevents(everyevent, 0);
- gDragDialog := NIL;
- END;
-
- BEGIN
- Initialize;
- DoDragDialog;
- END.
-
-
-
-